package cn.nai.DemoRan.demo02;

import java.awt.*;

public class Circle2 {
    public int x,y;
    private int r;
    public int vx,vy;
    public boolean isFilled = false;
    public Circle2(int x, int y, int r, int vx, int vy){
        this.x = x;
        this.y = y;
        this.r = r;
        this.vx = vx;
        this.vy = vy;
    }
    public int getR(){
        return r;
    }
    public void move(int minx,int miny,int maxx,int maxy){
        x+=vx;
        y+=vy;
        checkCollision(minx,miny,maxx,maxy);
    }
    public void checkCollision(int minx,int miny,int maxx,int maxy){
        if (x - r<minx){
            x = r;vx = -vx;
        }
        if (x + r >= maxx){
            x = maxx - r;vx = -vx;
        }
        if (y - r<minx){
            y = r;vy = -vy;
        }
        if (y + r>=maxx){
            y = maxy - r;vy = -vy;
        }

    }
    public boolean contain(Point p){
        return (x-p.x)*(x-p.x)+(y-p.y)*(y-p.y)<=r*r;
    }
}
